/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mock.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import mock.dto.AccountDTO;
import mock.utility.Utility;

public class OverDraftDAOImp implements OverDraftDAO {

    
	private Utility utility = new Utility();
	private AccountDAO accDAO = new AccountDAOImp();
	
	/**
	 * input: ODID
	 * output: overdraft value
	 */
    public double getOverDraftByODID(int ODID) {
        Connection con = utility.createConnection();
        if(con != null){
        	PreparedStatement ps = null;
        	ResultSet rs = null;
        	try {
				ps = con.prepareStatement("select * from OverDraft where ODID = ?");
				ps.setInt(1, ODID);
				rs = ps.executeQuery();
				if(rs.next()){
					double value = rs.getDouble("Value");
					return value;
				}else{
					return -1;
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return -1;
			}finally{
				if(con != null)
					try {
						con.close();
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				if(ps != null)
					try {
						ps.close();
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				if(rs != null)
					try {
						rs.close();
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
        }else{
        	return -1;
        }
    }
}
